package org.duang.push;

import org.duang.common.exceptios.ServiceException;
import org.duang.kit.ToolsKit;
import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 推送线程
 * 
 * @author laotang
 *
 */
public class PushThread extends Thread {

	private TextWebSocketFrame frame;
	private String[] pushIds;
	private static Logger logger = LoggerFactory.getLogger(PushThread.class);
	public PushThread(String[] pushIds, TextWebSocketFrame frame) {
		this.frame = frame;
		this.pushIds = pushIds;
	}

	public void run() {
		try {
			if (ToolsKit.isNotEmpty(frame.getText())) {
				WebSocket.getInstance().getWebSockerChannelHandler().send(pushIds, frame);
			} else {
				logger.warn("push message is null!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

}
